<template>
<div id="step5">
    <div class="page__bd personal-bd">
        <div class="weui-cells__title">用户信息</div>
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__hd">姓名</div>
                <div class="weui-cell__bd">
                    <p class="user-name">{{ $store.state.userName }}</p>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">手机号</div>
                <div class="weui-cell__bd">
                    <p id="user-phone">{{ $store.state.userPhone }}</p>
                </div>
            </div>
        </div>
    </div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cells__title">修改密码</div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">旧密码</label>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" v-model="oldPassword"  id="old_password" type="password" placeholder="请输入旧密码">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">新密码</label>
            </div>
            <div class="weui-cell__bd">
                <input v-model="newPassword" id="new_password" class="weui-input" type="password" placeholder="请输入新密码">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">确认新密码</label>
            </div>
            <div class="weui-cell__bd">
                <input v-model="newPassword2" id="new_password2" class="weui-input" type="password" placeholder="请再次输入新密码">
            </div>
        </div>
    </div>
    <div class="weui-btn-area">
        <a @click="changepwd" class="weui-btn weui-btn_primary" href="javascript:" id="submit_uppwd">提交</a>
    </div>
</div>
</template>

<script>
function changeBack () {

}
export default  {
    name: 'UserInfo',  // 组件名称
    data () {  // 数据
        return {
          msg: 'UserInfo',
          oldPassword:'',
          newPassword:'',
          newPassword2:''
        }
    },
    methods:{ // 自定义方法，可对data进行处理
        changepwd:function() {
            console.log("changepwd");
            if (this.oldPassword == "") {
                this.$store.commit("changeAlertContent","请输入旧密码！");
            } else if (this.newPassword == "") {
                this.$store.commit("changeAlertContent","请输入新密码！");
            } else if (this.newPassword != this.newPassword2) {
                this.$store.commit("changeAlertContent","两次新密码不一致");
            } else if(this.newPassword.length < 7 || this.newPassword.search(/\d/) == -1 || this.newPassword.search(/[a-zA-Z]/) == -1){
                this.$store.commit("changeAlertContent","新密码至少8位,且必须同时包含字母和数字");
            } else {
                this.$store.commit("changeIsLoading",true);
                $.post(uppwdServlet, {
                    oldPwd: this.oldPassword ,
                    newPwd: this.newPassword
                }, function(bdata) {
                    this.$store.commit("changeIsLoading",false);
                    if (bdata.code == "login_need") {
                        location.href = "./loding.html";
                    } else if (bdata.code == "0000") {
                        this.$store.commit("changeAlertContent","修改密码成功");
                    } else {
                        this.$store.commit("changeAlertContent","修改密码失败");
                    }

                }.bind(this));
            }
            this.$store.commit("changeIsAlert",true)
        }
    }
}
</script>

<style lang='scss' scoped>
.personal-bd .weui-cell__hd {
    width: 105px;
}
</style>
